package cn.jinjimi.app.custom.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.jinjimi.base.util.DateUtils;
import cn.jinjimi.app.R;
import cn.jinjimi.app.custom.entity.CustomLastedFollow;
import cn.jinjimi.app.interfaces.DataSetChangeListener;
import cn.jinjimi.app.main.adapter.extend.MyBaseAdapter;
import cn.jinjimi.app.main.widget.FrescoImageView.FrescoImageView;

/**
 * Created by Roy
 * Date: 17/1/9
 */

public class CustomLastFollowListAdapter extends MyBaseAdapter<CustomLastedFollow> {
    private Context mContext;
    private DataSetChangeListener dataSetChangeListener;

    public CustomLastFollowListAdapter(Context context, DataSetChangeListener listener) {
        this.mContext = context;
        this.dataSetChangeListener = listener;
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
        if (dataSetChangeListener != null)
            dataSetChangeListener.dataChange();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;

        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_insure_follow_plan_list, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        CustomLastedFollow item = getItem(position);

        holder.img.loadView(item.avatarUrl, R.drawable.list_icon_portrait);
        holder.tvName.setText(item.realName);
        holder.tvFollowTime.setText(DateUtils.formatyyyymmddhhmm(item.followTime));
        holder.tvContent.setText(item.content);

        return convertView;
    }

    public class ViewHolder {
        public FrescoImageView img;

        public RelativeLayout cardView;
        public TextView tvName;
        public TextView tvFollowTime;
        public TextView tvContent;

        public ViewHolder(View view) {
            img = (FrescoImageView) view.findViewById(R.id.img);
            img.asCircle();

            cardView = (RelativeLayout) view.findViewById(R.id.card_view);
            tvName = (TextView) view.findViewById(R.id.tv_title);
            tvFollowTime = (TextView) view.findViewById(R.id.tv_sec_title);
            tvContent = (TextView) view.findViewById(R.id.tv_third_title);
        }
    }

}
